package lucky.xiong.实际工作问题;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.util.Iterator;

public class 删除JSON数组里面的某一项 {
    public static void main(String[] args) throws IOException {
        String jsonStr = "[\n" +
                "  {\n" +
                "    \"database\": \"iam\",\n" +
                "    \"table\": [\n" +
                "      \"QRTZ\",\n" +
                "\t  \"TC_FRAMEWORK_DBSCRIPT_VERSION\",\n" +
                "      \"TD_FRAMEWORK_ADMIN_SESSION\",\n" +
                "      \"TD_FRAMEWORK_LICENSE\",\n" +
                "      \"FLYWAY_SCHEMA_HISTORY\",\n" +
                "      \"TD_AM_USER_SESSION\",\n" +
                "\t  \"TD_AM_USER_AUTHNED\",\n" +
                "\t  \"DATA_CENTER_CONFIG\",\n" +
                "\t  \"DATA_CENTER_RELATION\",\n" +
                "\t  \"DATA_CENTER_SYNC_PROGRESS\"\n" +
                "    ],\n" +
                "    \"ddl\": false,\n" +
                "    \"productName\": \"tac\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"database\": \"ida_data_service\",\n" +
                "    \"table\": [\n" +
                "      \"MONITOR_INFO\",\n" +
                "      \"user_online\"\n" +
                "    ],\n" +
                "    \"ddl\": false,\n" +
                "    \"productName\": \"tac\"\n" +
                "  }\n" +
                "]";
        JSONArray jsonObject = (JSONArray) JSONArray.parse(jsonStr);
        System.out.println(jsonObject.toJSONString());
        Iterator<Object> iterator = jsonObject.stream().iterator();
        while (iterator.hasNext()){
            JSONObject next = (JSONObject) iterator.next();
            JSONArray tableArray = next.getJSONArray("table");
            tableArray.remove("TD_AM_USER_SESSION");
        }
        System.out.println(jsonObject.toJSONString());
    }
}
